﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Delegate b = new Delegate();
            Buy buy = null;
            buy = new Buy(b.buyapple);
            buy += new Buy(b.buyorange);
            Console.WriteLine($"{buy("张三")}");
            b.whobuy("李四", buy);
            buy -= b.buyapple;
            b.whobuy("王二", buy);
            Console.ReadKey();
        }
    }
    delegate int Buy(string name);//定义委托对象 
    class Delegate
    {
        
        
        private string name;
        public int buyapple(string name)
        {
            Console.WriteLine("{0}购买苹果",name);
            return 10;
        }
        public int buyorange(string name)
        {
            Console.WriteLine("{0}购买橘子",name);
            return 10;
        }
        public int whobuy(string name,Buy buy)//委托对象作为参数
        {
            buy(name);
            return 10;
        }
    }
}
